//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.finance;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.OrderSet;
import com.aidong.dao.wills.PayListDao;
import com.aidong.model.wills.PayList;
import com.aidong.util.ExportXls;
import com.aidong.web.controller.BaseController;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"payList"})
public class PayListController extends BaseController {
    @Resource
    PayListDao payListDao;

    public PayListController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String dt1 = sdf.format(cal.getTime());
        return (new ModelAndView("finance/paylist/list")).addObject("payType", this.getTypeList("payType")).addObject("saleType", this.getTypeList("paySaleType")).addObject("dt1", dt1).addObject("dt2", dt1);
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "saleType",required = false) String saleType, @RequestParam(value = "payType",required = false) String payType, @RequestParam(value = "salesCode",required = false) String salesCode, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        ConditionMap cd = new ConditionMap();
        this.addConditionShopCode(cd, "shopCode", shopCode);
        cd.eq("saleType", saleType);
        cd.eq("payType", payType);
        if(!this.chkNull(salesCode)) {
            ConditionMap list = new ConditionMap(1);
            list.eq("salesCode", salesCode);
            list.eq("salesCode2", salesCode);
            cd.addSub(list);
        }

        if(this.chkNull(dateFrom) && this.chkNull(dateTo)) {
            SimpleDateFormat list1 = new SimpleDateFormat("yyyy-MM-dd");
            dateFrom = list1.format(new Date());
            dateTo = dateFrom;
        } else if(this.chkNull(dateFrom)) {
            dateFrom = dateTo;
        } else if(this.chkNull(dateTo)) {
            dateTo = dateFrom;
        }

        cd.ge("saleDate", this.getDateFrom(dateFrom));
        cd.le("saleDate", this.getDateTo(dateTo));
        List list2 = this.payListDao.queryList(cd, (new OrderSet()).asc("saleDate"));
        List saleTypeList = this.payListDao.getSumBySaleType(cd);
        List payTypeList = this.payListDao.getSumByPayType(cd);
        double sum = 0.0D;
        double saleTypeSum = 0.0D;
        double payTypeSum = 0.0D;

        Iterator mv;
        PayList pay;
        for(mv = list2.iterator(); mv.hasNext(); sum += pay.getAmount().doubleValue()) {
            pay = (PayList)mv.next();
        }

        for(mv = saleTypeList.iterator(); mv.hasNext(); saleTypeSum += pay.getAmount().doubleValue()) {
            pay = (PayList)mv.next();
        }

        for(mv = payTypeList.iterator(); mv.hasNext(); payTypeSum += pay.getAmount().doubleValue()) {
            pay = (PayList)mv.next();
        }

        ModelAndView mv1 = new ModelAndView("finance/paylist/_list");
        mv1.addObject("list", list2);
        mv1.addObject("saleTypeList", saleTypeList);
        mv1.addObject("payTypeList", payTypeList);
        mv1.addObject("sum", Double.valueOf(sum));
        mv1.addObject("saleTypeSum", Double.valueOf(saleTypeSum));
        mv1.addObject("payTypeSum", Double.valueOf(payTypeSum));
        return mv1;
    }

    @RequestMapping({"expt"})
    public ModelAndView expt(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "saleType",required = false) String saleType, @RequestParam(value = "payType",required = false) String payType, @RequestParam(value = "salesCode",required = false) String salesCode, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, HttpServletResponse response) {
        try {
            ConditionMap e = new ConditionMap();
            this.addConditionShopCode(e, "shopCode", shopCode);
            e.eq("saleType", saleType);
            e.eq("payType", payType);
            if(!this.chkNull(salesCode)) {
                ConditionMap list = new ConditionMap(1);
                list.eq("salesCode", salesCode);
                list.eq("salesCode2", salesCode);
                e.addSub(list);
            }

            if(this.chkNull(dateFrom) && this.chkNull(dateTo)) {
                SimpleDateFormat list1 = new SimpleDateFormat("yyyy-MM-dd");
                dateFrom = list1.format(new Date());
                dateTo = dateFrom;
            } else if(this.chkNull(dateFrom)) {
                dateFrom = dateTo;
            } else if(this.chkNull(dateTo)) {
                dateTo = dateFrom;
            }

            e.ge("saleDate", this.getDateFrom(dateFrom));
            e.le("saleDate", this.getDateTo(dateTo));
            List list2 = this.payListDao.queryList(e, (new OrderSet()).asc("saleDate"));
            List saleTypeList = this.payListDao.getSumBySaleType(e);
            List payTypeList = this.payListDao.getSumByPayType(e);
            ExportXls xls = new ExportXls(response, "支付流水", "支付流水");
            xls.addHead(new String[]{"单号", "门店编号", "门店名称", "销售日期", "销售类型", "合同号", "金额", "付款方式", "销售员1", "销售员2", "收银员"});
            xls.setWidth(new int[]{10, 10, 10, 20, 10, 15, 10, 15, 15, 15, 15});
            new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Iterator i$ = list2.iterator();

            PayList pay;
            while(i$.hasNext()) {
                pay = (PayList)i$.next();
                xls.addRow(new Object[]{pay.getAutoId(), pay.getShopCode(), this.cache.getValue("shopName", pay.getShopCode()), sdf2.format(pay.getSaleDate()), this.cache.getValue("paySaleType", pay.getSaleType()), pay.getContractCode(), pay.getAmount(), this.cache.getValue("payType", pay.getPayType()), this.nvl(pay.getSalesCode()) + " - " + this.nvl(this.cache.getValue("salesName", pay.getSalesCode())), this.nvl(pay.getSalesCode2()) + " - " + this.nvl(this.cache.getValue("salesName", pay.getSalesCode2())), this.nvl(pay.getCreateUser()) + " - " + this.nvl(this.cache.getValue("userName", pay.getCashier()))});
            }

            xls.addSheet("付款方式");
            xls.addHead(new String[]{"付款方式", "金额"});
            xls.setWidth(new int[]{15, 10});
            i$ = payTypeList.iterator();

            while(i$.hasNext()) {
                pay = (PayList)i$.next();
                xls.addRow(new Object[]{this.cache.getValue("payType", pay.getPayType()), pay.getAmount()});
            }

            xls.addSheet("销售类型");
            xls.addHead(new String[]{"销售类型", "金额"});
            xls.setWidth(new int[]{15, 10});
            i$ = saleTypeList.iterator();

            while(i$.hasNext()) {
                pay = (PayList)i$.next();
                xls.addRow(new Object[]{this.cache.getValue("paySaleType", pay.getSaleType()), pay.getAmount()});
            }

            xls.close();
            this.addUserLog("导出支付流水", list2.size() + "条记录");
        } catch (Exception var17) {
            this.log.error("import", var17);
        }

        return null;
    }
}
